package cn.shiro.shiroservice.auth.provider.interfaces.impl;

import cn.hutool.core.util.IdUtil;
import cn.shiro.shiroservice.auth.provider.absrtact.AbstractUserInfoAware;
import cn.shiro.shiroservice.auth.provider.interfaces.AuthPermissionFilter;
import cn.shiro.shiroservice.auth.provider.interfaces.AuthenticationInfoFilter;
import cn.shiro.shiroservice.auth.provider.interfaces.RealmSimple;
import org.apache.shiro.authc.*;
import org.apache.shiro.authc.pam.UnsupportedTokenException;
import org.apache.shiro.authz.permission.WildcardPermissionResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * &#064;Time 2023 十二月 星期四 14:14
 *
 * @author ShangGuan
 * 一个简单的Realm
 */

public class SimpleRealmImpl extends AbstractUserInfoAware implements RealmSimple {

    private static final Logger logger = LoggerFactory.getLogger(SimpleRealmImpl.class);


    public SimpleRealmImpl(AuthPermissionFilter authPermissionFilter, DefaultRolePermissionResolver defaultRolePermissionResolver, AuthenticationInfoFilter authenticationInfoFilter) {
        super(new WildcardPermissionResolver(),defaultRolePermissionResolver,authPermissionFilter,authenticationInfoFilter);
    }

    @Override
    public String getName() {
        return getClass().getName() + "_" + IdUtil.simpleUUID();
    }

    /**
     * 判断传入的AuthenticationToken是否是支持的 权限Token类
     *
     * @param token 代币
     * @return boolean
     */

    @Override
    public boolean supports(AuthenticationToken token) {
        //判断实现了AuthenticationToken
        if (token instanceof HostAuthenticationToken && token instanceof RememberMeAuthenticationToken) return true;
        logger.warn(token.getClass()+"应该是继承或者实现"+"("+HostAuthenticationToken.class+")"+"and"+"("+RememberMeAuthenticationToken.class+")");
        throw new UnsupportedTokenException("Not Know AuthenticationToken");
    }


    @Override
    protected void save(String key, Object param) {

    }
}
